$(function () {
    $("#jqGrid").jqGrid({
        url: baseURL + 'sys/log/list',
        datatype: "json",
        colModel: [
            {label: 'id', name: 'id', width: 30, index: "id", key: true},
            {label: '用户名', name: 'username', width: 50},
            {label: '用户操作', name: 'operation', width: 70},
            {label: '请求方法', name: 'method', width: 150},
            {label: '请求参数', name: 'params', width: 80},
            {label: '执行时长(毫秒)', name: 'time', width: 80},
            {label: 'IP地址', name: 'ip', width: 70},
            {label: '创建时间', name: 'createDate', width: 90}
        ],
        viewrecords: true,
        height: 425,
        rowNum: 10,
        rowList: [10, 20, 30, 40, 50, 60, 100],
        rownumbers: true,
        rownumWidth: 30,
        autowidth: true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader: {
            root: "data.page.list",
            page: "data.page.currPage",
            total: "data.page.totalPage",
            records: "data.page.totalCount"
        },
        prmNames: {
            page: "page",
            rows: "limit",
            order: "order"
        },
        gridComplete: function () {
            //隐藏grid底部滚动条
            $("#jqGrid").closest(".ui-jqgrid-bdiv").css({"overflow-x": "hidden"});
        }
    });
});

var vm = new Vue({
    el: '#pmpapp',
    data: {
        q: {
            key: null
        }
    },
    methods: {
        query: function () {
            vm.reload();
        },

        reload: function (event) {
            var page = $("#jqGrid").jqGrid('getGridParam', 'page');
            $("#jqGrid").jqGrid('setGridParam', {
                postData: {'key': vm.q.key},
                page: page
            }).trigger("reloadGrid");
        },

        truncate: function () {
            confirm('骚年，清空了可就没有了哦，确定要清除日志？', function () {
                $.ajax({
                    type: "POST",
                    url: baseURL + "sys/log/truncate",
                    success: function (r) {
                        if (r.code == 0) {
                            alert('操作成功，赶紧跑路吧，骚年！', function () {
                                vm.reload();
                            });
                        } else {
                            alert(r.msg);
                        }
                    }
                });
            });
        }
    }
});